import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_security_risk_grading_control_list_app_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/task_implementation_page/task_implementation_controller.dart';

/// 风险管控清单
class TaskImplementationPage extends StatelessWidget {
  TaskImplementationPage({super.key}){
    Get.lazyPut(TaskImplementationController.new);
  }
  @override
  Widget build(BuildContext context) {
    final TaskImplementationController controller = Get.find<TaskImplementationController>();
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
              key: controller.riskRightScaffoldKey,
              body: Container(
                color: AppColors.bg_color_grey,
                padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Expanded(child: _getBox(controller)),
                      ],
                    ),
                    AppGaps.vGap10,
                    Container(
                      padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 10.w),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8),
                        color: Colors.white,
                      ),
                      child: Stack(
                        children: [
                          const Row(),
                          SvgPicture.asset(AppImages.icon_not_implemented, height: 46.w),
                          Positioned(
                            right: 0,
                            child: SvgPicture.asset(AppImages.icon_implemented, height: 46.w),
                          ),
                          Positioned(
                            left: 16,
                            top: 12,
                            child: Row(
                              children: [
                                Row(
                                  children: [
                                    Text(
                                      '未落实',
                                      style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xFF252F81)),
                                    ),
                                    AppGaps.hGap14,
                                    Text(
                                      '${controller.getTaskPracticableStatusEntity?.notImplemented}',
                                      style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500, color: const Color(0xFF252F81)),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                          Positioned(
                            right: 16,
                            top: 12,
                            child: Row(
                              children: [
                                Row(
                                  children: [
                                    Text(
                                      '${controller.getTaskPracticableStatusEntity?.implemented}',
                                      style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500, color: Colors.white),
                                    ),
                                    AppGaps.hGap14,
                                    Text(
                                      '已落实',
                                      style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: Colors.white),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    AppGaps.vGap12,
                    Expanded(
                        child: CustomEasyRefreshList<GetSecurityRiskGradingControlListAppEntity>(
                      key: controller.globalKey,
                      dataLoad: (i, size, {String? search}) {
                        return controller.getTaskData(i, size);
                      },
                      itemBuilder: (item, index) {
                        return CustomTitleChartPage(
                            // title: '${item.riskMeasureName}',
                            title: '${item.riskMeasureDesc}',
                            titleRightWidget: _getResult(item.practicableStatus),
                            child: Column(
                              children: [
                                Row(
                                  children: [
                                    Text(
                                      '管控手段：',
                                      style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                                    ),
                                    const Spacer(),
                                    Text(
                                      item.dataSrcControlLabel ?? '',
                                      style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xff495061)),
                                    ),
                                  ],
                                ),
                                AppGaps.vGap10,
                                Row(
                                  children: [
                                    Text(
                                      '详情：',
                                      style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                                    ),
                                    const Spacer(),
                                    Container(
                                      padding: EdgeInsets.only(left: 10.w, right: 2.w, top: 2.w, bottom: 2.w),
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(5),
                                        color: const Color(0xFF5C6DFF).withOpacity(0.1),
                                      ),
                                      child: Row(
                                        children: [
                                          Text(
                                            '任务详情',
                                            style: TextStyle(
                                              color: const Color(0xFF5C6DFF),
                                              fontSize: 12.sp,
                                              fontWeight: FontWeight.w400,
                                            ),
                                          ),
                                          SvgPicture.asset(
                                            AppImages.icon_right_arrow,
                                          ),
                                          AppGaps.hGap2,
                                        ],
                                      ).click(controller.onTaskButtonPressed),
                                    )
                                  ],
                                ),
                              ],
                            ).click(() {
                              controller.onTaskDetailButtonPressed(item);
                            }));
                      },
                    ))
                  ],
                ),
              ),
              // endDrawer: CustomEndDrawer(
              //   centerContext: Column(
              //     children: [
              //       RegionalOrganizationTreePage(
              //         selectedEntity: controller.selectedEntity,
              //         onCallBack: (RiskTreeEntity entity) {
              //           controller.selectedEntity = entity;
              //         },
              //       ),
              //     ],
              //   ),
              //   reset: controller.reset,
              //   confirm: controller.confirm,
              // ),
          );
        });
  }

  Widget _getBox(TaskImplementationController controller) {
    return Container(
      padding: EdgeInsets.all(12.w),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: Text(
              '${controller.title}',
              style: TextStyle(
                color: const Color(
                  0xFF495061,
                ),
                fontWeight: FontWeight.w500,
                fontSize: 12.sp,
              ),
            ),
          ),
          Row(
            children: [
              _divider(),
              AppGaps.hGap8,
              Container(
                width: 38.w,
                height: 38.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
                child: SvgPicture.asset(
                  AppImages.icon_search_screen,
                  width: 16.w,
                ),
              ).click(controller.onFilterButtonPressed),
            ],
          ),
        ],
      ),
    ).click(controller.onFilterButtonPressed);
  }

  // 落实结果
  Widget _getResult(String? i) {
    switch (i) {
      case '已落实':
        return _title('已落实', const Color(0xFF5C6DFF));
      case '未落实':
        return _title('未落实', const Color(0xFFFD6B6B));
      default:
        return _title('未知', Colors.red);
    }
  }

  Widget _title(String title, Color color) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 11.w),
      decoration: BoxDecoration(
          color: color,
          borderRadius: const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10),
            bottomRight: Radius.circular(10),
          )),
      child: Text(
        title,
        style: TextStyle(
          color: Colors.white,
          fontSize: 10.sp,
          fontWeight: FontWeight.w400,
        ),
      ),
    );
  }

  ///分割线
  Widget _divider() {
    return Container(
      width: 1.w,
      height: 40.w,
      decoration: const BoxDecoration(
          gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [
        Color(0x00649FFF),
        Color(0xFF649FFF),
        Color(0x00649FFF),
      ])),
    );
  }

}
